/**
 * Created by Administrator on 2017/2/15 0015.
 */

const userManagement = require('../controller/user-controller.js');
const loginApi = {
    login (req, res) {

        let loginAccount = req.body.loginAccount,
            loginPassword = req.body.loginPassword,
            verifyCode = req.body.verifyCode,
            params = {loginAccount, loginPassword};

        if (!loginAccount || !loginPassword || !verifyCode) {
            res.status(400).json({message: 'params missed.'});
            return
        }

        return userManagement
            .login(params)
            .then((data) => {
                res.json({
                    result: data.result,
                    message: data.message
                });
            }, (err) => {
                res.status(err.status).json({
                    message: err.message
                });
            })
    }
};

module.exports = loginApi;